home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
-
- #include <X11/Intrinsic.h>
- #include <Xm/Xm.h>
- #include <Xm/Form.h>
- #include <Xm/Label.h>
- #include <Xm/Text.h>
- #include <Xm/TextF.h>
- #include <Xm/Separator.h>
-
- #include "vroom.h"
- #include "client.h"
- #include "car.h"
-
- /* BEGIN PROTOTYPES -S messages.c */
- static void sendMessage( Widget w, XtPointer clientData,
- XtPointer callData ) ;
- /* END PROTOTYPES -S messages.c */
-
- #define VISIBLE_LINES (5)
- #define LINE_LENGTH (VROOM_NAMELEN+3+VROOM_MSGLEN)
-
- extern Widget topLevel ;
- extern Widget introWindow ;
- extern Widget messageForm ;
- extern Car cars[] ;
-
- static Widget textArea = NULL ;
- static char line[VISIBLE_LINES][LINE_LENGTH] ;
- static char nextLine = 0 ;
- static char numLines = 0 ;
-
-
-
- /*------------------------------------------------------------------------------
- * Create the message area.
- *----------------------------------------------------------------------------*/
- void
- createMessageArea(
- void
- )
- {
- int n ;
- Arg args[10] ;
- XmString str ;
- Widget separator ;
- Widget label ;
- Widget tf ;
-
- if( textArea != NULL )
- {
- return ;
- }
-
- n = 0 ;
- XtSetArg( args[n], XmNorientation, XmHORIZONTAL ) ; n++ ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_NONE ) ; n++ ;
- separator = XtCreateManagedWidget( "separator", xmSeparatorWidgetClass,
- messageForm, args, n ) ;
-
- n = 0 ;
- str = XmStringCreateLocalized( "Incoming messages:" ) ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNtopWidget, separator ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_NONE ) ; n++ ;
- XtSetArg( args[n], XmNlabelString, str ) ; n++ ;
- XtSetArg( args[n], XmNalignment, XmALIGNMENT_BEGINNING ) ; n++ ;
- label = XtCreateManagedWidget( "label", xmLabelWidgetClass,
- messageForm, args, n ) ;
- XmStringFree( str ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNrows, VISIBLE_LINES ) ; n++ ;
- XtSetArg( args[n], XmNeditMode, XmMULTI_LINE_EDIT ) ; n++ ;
- XtSetArg( args[n], XmNeditable, False ) ; n++ ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNtopWidget, label ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_NONE ) ; n++ ;
- textArea = XtCreateManagedWidget( "incomingText", xmTextWidgetClass,
- messageForm, args, n ) ;
-
- XmTextSetString( textArea, "" ) ;
-
- n = 0 ;
- str = XmStringCreateLocalized( "Outgoing message:" ) ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNtopWidget, textArea ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_NONE ) ; n++ ;
- XtSetArg( args[n], XmNlabelString, str ) ; n++ ;
- XtSetArg( args[n], XmNalignment, XmALIGNMENT_BEGINNING ) ; n++ ;
- label = XtCreateManagedWidget( "label", xmLabelWidgetClass,
- messageForm, args, n ) ;
- XmStringFree( str ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNtopWidget, label ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNmaxLength, VROOM_MSGLEN - 1 ) ; n++ ;
- tf = XtCreateManagedWidget( "outgoingText", xmTextFieldWidgetClass,
- messageForm, args, n ) ;
-
- XtAddCallback( tf, XmNactivateCallback, sendMessage, NULL ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Send a message to the server.
- *----------------------------------------------------------------------------*/
- static void
- sendMessage(
- Widget w,
- XtPointer clientData,
- XtPointer callData
- )
- {
- char *msg ;
- char *p ;
-
- msg = XmTextFieldGetString( w ) ;
-
- if( ( p = strchr( msg, '\n' ) ) != NULL )
- {
- *p = '\0' ;
- }
-
- if( strlen( msg ) )
- {
- sendServerMsgPacket( msg ) ;
- }
-
- XtFree( msg ) ;
-
- XmTextFieldSetString( w, "" ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Post a new message to the screen.
- *----------------------------------------------------------------------------*/
- void
- postNewMessage(
- int nPlayer,
- char *msg
- )
- {
- int i ;
- int l ;
- int n ;
- int k ;
- char text[VISIBLE_LINES*(LINE_LENGTH+1)+1] ;
-
- if( nPlayer < 0 )
- {
- l = 0 ;
- }
- else
- {
- l = strlen( cars[nPlayer].name ) ;
- strncpy( line[nextLine], cars[nPlayer].name, l ) ;
- line[nextLine][l++] = ':' ;
- line[nextLine][l++] = ' ' ;
- }
- k = 0 ;
- while( k < VROOM_MSGLEN - 1 && msg[k] != '\0' && msg[k] != '\n' )
- {
- line[nextLine][l++] = msg[k++] ;
- }
- line[nextLine][MINFUNC( l, LINE_LENGTH-1 )] = '\0' ;
-
- n = nextLine - numLines ;
- if( n < 0 )
- {
- n = ( n + VISIBLE_LINES + 1 ) % VISIBLE_LINES ;
- }
-
- nextLine = ( nextLine + 1 ) % VISIBLE_LINES ;
- if( numLines < VISIBLE_LINES )
- {
- numLines = numLines + 1 ;
- }
-
- l = 0 ;
- for( k = 0 ; k < numLines ; k++ )
- {
- i = 0 ;
- while( line[n][i] != '\0' )
- {
- text[l++] = line[n][i++] ;
- }
- text[l++] = '\n' ;
-
- n = ( n + 1 ) % VISIBLE_LINES ;
- }
- text[l++] = '\0' ;
-
- XmTextSetString( textArea, text ) ;
- }
-
-
-
-